<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="__PUBLIC__/echarts/echarts.min.js"></script>
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
</head>
<style>

    .layui-table th, .layui-table td{
        padding: 9px 6px;
        text-align: center;
    }
    .operation-menu a{
        margin: 5px 0;!important;
    }
    /*.layui-form select{*/
    /*display: inline-block;*/
    /*}*/
</style>
<body>
<div class="layui-fluid main">
    <fieldset class="layui-elem-field site-demo-button" style="margin-top: 30px;border:0">
        <div class="layui-form-item" style="float: left;">
            <form class="layui-form serch" action="{:url('admin/Coupon/index')}" method="post">
                <div class="layui-form-item" style="float: left;">


                    <div class="layui-input-inline">
                        <input type="text" name="coupon_name" value="{if isset($wherelist['coupon_name'])}{$wherelist['coupon_name']}{/if}" lay-verify="title" autocomplete="off" placeholder="请输入优惠券名称" class="layui-input layui-btn-sm">
                    </div>
                    <div class="layui-input-inline">
                        <div class="layui-inline">
                            <select name="coupon_types" lay-search="">
                                <option value="">优惠券类型</option>
                                <option value="1" {if isset($wherelist['coupon_types']) AND $wherelist['coupon_types']==1 }selected{/if}>折扣</option>
                                <option value="2" {if isset($wherelist['coupon_types']) AND $wherelist['coupon_types']==2 }selected{/if}>满减</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-input-inline">
                        <div class="layui-inline">
                            <select name="coupon_status" lay-search="">
                                <option value="">活动状态</option>
                                <option value="1" {if isset($wherelist['coupon_status']) AND $wherelist['coupon_status']==1 }selected{/if}>未开始</option>
                                <option value="2" {if isset($wherelist['coupon_status']) AND $wherelist['coupon_status']==2 }selected{/if}>进行中</option>
                                <option value="3" {if isset($wherelist['coupon_status']) AND $wherelist['coupon_status']==3 }selected{/if}>已结束</option>
                                <option value="4" {if isset($wherelist['coupon_status']) AND $wherelist['coupon_status']==4 }selected{/if}>已停用</option>
                            </select>
                        </div>
                    </div>


                    <button class="layui-btn layui-btn-danger layui-btn-sm" lay-submit="" lay-filter="serch">搜索</button>
                    <a href="{:url('admin/coupon/addcoupon')}" class="layui-btn layui-btn-sm a_menu">
                        新建优惠
                    </a>

                </div>
            </form>

        </div>
    </fieldset>
    <table class="layui-table" lay-even="" lay-skin="line">
        <colgroup>
            <col width="4%">
            <col width="15%">
            <col width="7%">
            <col width="5%">
            <col width="5%">
            <col width="5%">
            <col width="8.3%">
            <col width="6%">
            <col width="8%">
            <col width="8%">
            <col width="8%">
            <col width="8%">
            <col width="8%">
            <col width="5%">
            <col width="10%">
        </colgroup>
        <thead>

        <tr>
            <th>ID</th>
            <th>名称</th>
            <th>面值</th>
            <th>总数</th>
            <th>已领取</th>
            <th>活动状态</th>
            <th>使用范围</th>
            <th>限制领取</th>
            <th>创建时间</th>
            <th>开始领取时间</th>
            <th>结束领取时间</th>
            <th>开始使用时间</th>
            <th>结束使用时间</th>
            <th>操作人</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name='lie' id='vo'}
        <tr>
            <td>{$vo.coupon_id}</td>
            <td>{$vo.coupon_name}</td>
            <td>{$vo.coupon_discount}</td>
            <td>{$vo.coupon_quantity}</td>
            <td>{$vo.coupon_alreadyreceived}</td>
            <td>
                {switch name="vo.coupon_status"}
                {case value=""}未知{/case}
                {case value="1"}未开始{/case}
                {case value="2"}进行中{/case}
                {case value="3"}已结束{/case}
                {case value="4"}停止中{/case}
                {default /}default
                {/switch}
            </td>
            <td>{$vo.name}</td>
            <td>{$vo.receive_limit}</td>
            <td><?= date('Y-m-d H:i:s',$vo['creattime']) ?></td>
            {if($vo.time_rece_type == 1)}
            <td>无限制</td>
            <td>无限制</td>
            {else/}
            <td>{$vo['etart_receivetime']|date='Y-m-d H:i:s',###}</td>
            <!--<td><?php //echo date('Y-m-d H:i:s',$vo['end_receivetime']); ?></td>-->
            <td>
                <?php $vo['end_receivetime']= (int)$vo['end_receivetime']; ?>
                {$vo['end_receivetime']|date='Y-m-d H:i:s',###}</td>
            {/if}

            {if($vo.time_use_type == 1 || $vo.time_use_type == 3 )}
            <td>无限制</td>
            <td>无限制</td>
            {else/}
                    <td><?= date('Y-m-d H:i:s',$vo['etart_usetime']) ?></td>
                    <td><?= date('Y-m-d H:i:s',$vo['end_usetime']) ?></td>
            {/if}

            <td>{$vo.admin.nickname}</td>
            <td class="operation-menu">

                <a href="{:url('admin/coupon/edit')}?id={$vo.coupon_id}" class="layui-btn layui-btn-xs  a_menu"  style="margin-right: 0;font-size:12px">修改</a>
                <a href="{:url('admin/coupon/copy')}?id={$vo.coupon_id}" codeid="{$vo.coupon_id}" class="layui-btn layui-btn-xs layui-btn-warm a_menu copy"  style="margin-right: 0;font-size:12px;background: #FF5722">复制</a>
                <a href="{:url('admin/coupon/distributed')}?id={$vo.coupon_id}" class="layui-btn layui-btn-xs layui-btn-warm a_menu"  style="margin-right: 0;font-size:12px;background: #FF5722">派发</a>


                {switch name="vo.coupon_status"}
                {case value=""}<a href="####" class="layui-btn layui-btn-xs " codeid="{$vo.coupon_id}" disabled title="结束" style="margin-right: 0;font-size:12px;">无操作</a>{/case}
                {case value="1"}<a href="#" class="layui-btn layui-btn-xs  stop" codeid="{$vo.coupon_id}" title="开始" style="margin-right: 0;font-size:12px;">开始</a>{/case}
                {case value="2"}<a href="#" class="layui-btn layui-btn-xs layui-btn-danger stop" codeid="{$vo.coupon_id}" title="提前结束" style="margin-right: 0;font-size:12px; background: red">结束</a>{/case}
                {case value="3"}<a href="####" class="layui-btn layui-btn-xs layui-btn-danger" codeid="{$vo.coupon_id}" disabled title="结束" style="margin-right: 0;font-size:12px;background-color: #777777">结束</a>{/case}
                {case value="4"}<a href="#" class="layui-btn layui-btn-xs  stop" codeid="{$vo.coupon_id}" title="继续" style="margin-right: 0;font-size:12px; background: #FF5722">继续</a>{/case}
                {default /}default
                {/switch}
                <!--<a class="layui-btn layui-btn-xs layui-btn-danger delete"  codeid="{//$vo.coupon_id}" style="margin-right: 0;font-size:12px;">删除</a>-->
                <a href="{:url('admin/coupon/details')}?id={$vo.coupon_id}" class="layui-btn layui-btn-xs layui-btn-danger a_menu"  codeid="{$vo.coupon_id}" style="margin-right: 0;font-size:12px;">详情</a>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <div>{$lie->render()}</div>

    <script src="__PUBLIC__/layui/layui.js"></script>
    <script src="__PUBLIC__/jquery/jquery.min.js"></script>

    <script>
        var message;
        layui.config({
            base: '__JS__/',
            version: '1.0.1'
        }).use(['app', 'message'], function() {
            var app = layui.app,
                $ = layui.jquery,
                layer = layui.layer;
            //将message设置为全局以便子页面调用
            message = layui.message;
            //主入口
            app.set({
                type: 'iframe'
            }).init();
        });
    </script>
    <script type="text/javascript">

        $('.delete').click(function(){
            var id = $(this).attr('codeid');
            layer.confirm('确定要删除?', function(index) {
                $.ajax({
                    url:"{:url('admin/coupon/delcoupon')}",
                    data:{id:id},
                    success:function(res) {
                        layer.msg(res.msg);
                        if(res.code == 1) {
                            setTimeout(function(){
                                location.reload();
                            },1500)
                        }
                    }
                })
            })
        })
        $('.stop').click(function(){
            var id = $(this).attr('codeid');
            layer.confirm('是否确定操作？', function(index) {
                $.ajax({
                    url:"{:url('admin/coupon/stop')}",
                    data:{id:id},
                    success:function(res) {
                        layer.msg(res.msg);
                        if(res.code == 1) {
                            setTimeout(function(){
                                location.reload();
                            },1500)
                        }
                    }
                })
            })
        })



        // $('.copy').click(function(){
        //     var id = $(this).attr('codeid');
        //     layer.confirm('确定复制吗?', function(index) {
        //         $.ajax({
        //             url:"{:url('admin/trip/copytrip')}",
        //             data:{id:id},
        //             success:function(res) {
        //                 layer.msg(res.msg);
        //                 if(res.code == 1) {
        //                     setTimeout(function(){
        //                         location.reload();
        //                     },1500)
        //                 }
        //             }
        //         })
        //     })
        // })

    </script>
    <script type="text/javascript">
        layui.use('layer', function(){
            var layer = layui.layer;
            $('.a_menu').click(function(){
                var url = $(this).attr('href');
                var a = 0;
                $.ajax({
                    url:url
                    ,async:false
                    ,success:function(res){
                        if(res.code == 0) {
                            layer.msg(res.msg);
                            a = 1;
                        }
                    }
                })
                if(a === 0) {
                    layer.open({
                        type:2,
                        content:url,
                        area: ['700px', '680px'],
                        end:function(){
                            location.reload();
                        }
                    });
                }
                return false;
            })

            $('.preview').click(function(){
                var url = $(this).attr('href');
                layer.open({
                    type:2,
                    content:url,
                    area: ['550px', '400px']
                });
                return false;
            })
        });
    </script>

</body>
</html>
